ARG BUILD_TYPE

FROM golang:alpine AS builder

LABEL AUTHOR="monoliths-uni@outlook.com"

# Go Compile Define
ENV GO111MODULE=on \
    GOPROXY=https://goproxy.cn,direct \
    CGO_ENABLED=0 \
    GOOS=linux \
    GOARCH=amd64

# Prepare SSL

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories

RUN apk update && apk upgrade && apk add --no-cache ca-certificates make
RUN apk --no-cache add tzdata
RUN update-ca-certificates

ENV BUILDER_DIR="/root/simple_updater"

RUN mkdir -p $BUILDER_DIR

COPY . $BUILDER_DIR

# build

RUN cd /root/simple_updater && make build

FROM scratch

# get SSL
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# get TMZONE
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo

COPY --from=builder /root/simple_updater/out/simple_updater /simple_updater

# Enable Asia Timezone
ENV TZ=Asia/Shanghai

# Prepare For Run
ENV SERVER_PATH="/"

WORKDIR $SERVER_PATH

# EXPOSE 8080

ENTRYPOINT ["/simple_updater"]
